package ru.pashkan.db.dao.springjdbc;

import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import ru.pashkan.db.dao.SitesDao;
import ru.pashkan.entity.Site;

import ru.pashkan.db.dao.springjdbc.mapper.SitesMapper;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SitesJdbcDao extends AbstractSpringJdbc implements SitesDao {

//    private JdbcTemplate jdbcTemplate;
//
//    public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
//        this.jdbcTemplate = jdbcTemplate;
//    }
    private String tableName = "sites";

    @Override
    public void saveSite(Site site) {
//        this.getJdbcTemplate().update(
//                "INSERT INTO "+ tableName +" (siteName, siteUrl, siteType, clientID, startDate, endDate) " +
//                "VALUES (:siteName, :siteUrl, :siteType, :clientID, :startDate, :endDate)",
//                new MapSqlParameterSource()
//                .addValue("siteName", site.getSiteName())
//                .addValue("siteUrl", site.getSiteUrl())
//                .addValue("siteType", site.getSiteType())
//                .addValue("clientID", site.getClientID())
//                .addValue("startDate", site.getStartDate())
//                .addValue("endDate", site.getEndDate())
//        );
//        this.getJdbcTemplate().update(
//                "INSERT INTO SITES (siteName) " +
//                "VALUES (:siteName)",
//                new MapSqlParameterSource()
//                .addValue("siteName", site.getSiteName())
//
//
//                );
        this.getJdbcTemplate().update(
                "INSERT INTO "+ tableName +" (siteName, siteUrl, siteType, clientID, startDate, endDate) " +
                "VALUES (?, ?, ?, ?, ?, ?)",
                new Object[] {site.getSiteName(), site.getSiteUrl(), site.getSiteType(), site.getClientID(), site.getStartDate(), site.getEndDate()}
        );
    }

    @Override
    public List<Site> takeSite() {
        return this.getJdbcTemplate().query("SELECT * FROM SITES", new SitesMapper());
        //To change body of implemented methods use File | Settings | File Templates.   return (Site) jdbcTemplate.query("SELECT * FROM SITES", new SitesMapper());

    }
}
